<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" ></meta>
	<#include "../common.html" />
</head>
<body>
	<div  class="easyui-panel" data-options="fit:true,border:false">
		<div id="roleForm" style="margin: 20px 140px;">
			<#list roles as role>
			<div style="margin-bottom: 10px;">
				<input type="checkbox" id="${role.id}" value="${role.id}"/>
				<label for="${role.id}">${role.name}</label>
			</div>
			</#list>
		</div>
	<script>
		var id = ${id};
		$.ajax({
			url: "/admin/role/getUserRole",
			data:  JSON.stringify({"id":id}),
			contentType: "application/json; charset=utf-8",
			type: "POST",
			dataType: 'json',
			success: function(data){
				if (data.success) {
					var userRoles = data.obj;
					for (var content in userRoles) {
						$("#"+userRoles[content].rid).attr("checked","checked")
					}
				}
			}
		});

		function submitRole($roleDialog,$pjq){
			var userRole = [];
			$("input[type='checkbox']:checked").each(function(){
				userRole.push({"uid": id, 'rid': $(this).val()})
			})
			$.ajax({
				url: "/admin/role/modifyUserRole",
				data:  JSON.stringify(userRole),
				contentType: "application/json; charset=utf-8",
				type: "POST",
				dataType: 'json',
				success: function(result){
					if(result.success){
						$pjq.messager.alert('提示', result.msg, 'info',function(r){
							$roleDialog.dialog('destroy');
						});
					}else{
						$pjq.messager.alert('错误',result.msg,'error');
					}
				}
			});
	}
	</script>
	</div>
</body>
</html>